<%@ page contentType="text/html;charset=UTF-8" import="java.sql.*" %>
<%
    String JDBC_DRIVER = "com.mysql.jdbc.Driver";
    String DB_URL = "jdbc:mysql://localhost:3306/sims";
    String USER = "root";
    String PASS = "123456";

    Class.forName(JDBC_DRIVER);
    Connection conn = DriverManager.getConnection(DB_URL, USER, PASS);

    String countQuery = "SELECT count(*) FROM student";
    PreparedStatement countPsmt = conn.prepareStatement(countQuery);
    ResultSet countRs = countPsmt.executeQuery();
    countRs.next();

    String sql = "SELECT * FROM student";
    PreparedStatement psmt = conn.prepareStatement(sql);
    ResultSet rs = psmt.executeQuery();
%>
<style>
    body {
        font-family: Arial, sans-serif;
        margin: 0;
        padding: 0;
        background-color: #f2f2f2;
    }

    h1 {
        text-align: center;
        color: #333;
    }

    table {
        width: 80%;
        margin: 20px auto;
        border-collapse: collapse;
    }

    th,
    td {
        padding: 10px;
        text-align: center;
        border: 1px solid #ddd;
    }

    tr:nth-child(odd) {
        background-color: #f9f9f9;
    }

    tr:hover {
        background-color: #e1e1e1;
    }

    input[type="text"],
    input[type="button"] {
        padding: 5px;
        border-radius: 4px;
        border: 1px solid #ccc;
    }

    input[type="button"] {
        cursor: pointer;
        background-color: #3498db;
        color: white;
    }

    input[type="button"]:hover {
        background-color: #2980b9;
    }

    a {
        display: block;
        text-align: center;
        margin-top: 20px;
        text-decoration: none;
        color: #333;
    }
</style>
<html>
<head>
    <title>学生信息</title>
</head>
<body>
<h1>学生信息</h1>
<script>
    function del(studentId) {
        window.location.href = "del.jsp?id=" + studentId;
    }
</script>
<table border="1">
    <tr>
        <th>学号</th>
        <th>姓名</th>
        <th>性别</th>
        <th>手机号码</th>
        <th>删除</th>
        <th>修改</th>
    </tr>
    <%
        while (rs.next()) {
            int Id = rs.getInt(1);
            String name = rs.getString(2);
            String gender = rs.getString(3);
            String phone = rs.getString(4);
    %>
    <tr>
        <td><input name="id" value="<%=Id%>" /></td>
        <td><input type="text" name="name" value="<%=name%>" /></td>
        <td><input type="text" name="gender" value="<%=gender%>" /></td>
        <td><input type="text" name="phone" value="<%=phone%>" /></td>
        <td><input type="button" value="删除" onclick="del(<%=Id%>)"></td>
        <td><a href="edit_info.jsp?id=<%=Id%>">修改</a></td>
    </tr>
    <%
        }
    %>
</table>
<a href="increase_info.jsp">添加学生信息</a>
<a href="modify_pwd.jsp">修改密码</a>
<a href="login.jsp">退出</a>
</body>
</html>